//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES OR INDEMNITIES.
//
//
// (C) Copyright 2006 Marvell International Ltd.
// All Rights Reserved
//

#include <windows.h>
#include <types.h>
#include <string.h>
#include <stdio.h>
#include <tchar.h>
#include <nkintr.h>

#include <monahans.h>
#include <ceddk.h>
#include "args.h"
#include "ebootcfg.h"
#include "ioctl_cfg.h"

#include "DispDrvr.h"
#define  DEFINE_CURSOR_GLOBALS
#include "xllp_defs.h"
#include "xllp_lcd.h"
#include "xllp_bcr.h"

#include "xllp_lcd_plat.h"

#include "arava.h"

extern XLLP_LCD_T XllpLCD;
extern XLLP_MINI_LCD_T XllpMiniLCD;

UINT get_blit_option()
{
    DWORD out_size;
    BSP_ARGS args;

    KernelIoControl(IOCTL_GET_BSP_ARGS, NULL, 0, 
                    &args, sizeof(BSP_ARGS), &out_size);

    return args.DefaultBlit;
}

#if 0
static DWORD get_panel_type()
{
    DWORD out_size;
    BSP_ARGS args;

    KernelIoControl(IOCTL_GET_BSP_ARGS, NULL, 0, 
                    &args, sizeof(BSP_ARGS), &out_size);

    return args.eBootCFG.drvCfg[CFG_LCD_PANEL];
}

static void init_dual_panel(int panel_is_leaded, int dual_panel_mode)
{

    NKDbgPrintfW(TEXT("using lcd panel VGA QVGA OLED(VGA) %s %s.\r\n"), 
                 panel_is_leaded? L"leaded" : L"lead free",
                 dual_panel_mode == MODE_QVGA? L"QVGA" : L"VGA");
    XllpLCDInit_VGA_QVGA_OLED(&XllpLCD, dual_panel_mode, panel_is_leaded);
}

BOOL is_dual_panel()
{
    DWORD cfg = get_panel_type();
    switch (cfg)
    {
    case XLLP_LCD_PANEL_ID_VGA_QVGA_OLED_LEAD:
    case XLLP_LCD_PANEL_ID_VGA_QVGA_OLED_LEAD_FREE:
    case XLLP_LCD_PANEL_ID_VGA_QVGA_OLED_LEAD_FREE_LANDSCAPE:
        return TRUE;
    default:
        return FALSE;
    }
    return FALSE;
    return FALSE;
}
#endif	

void panel_select(UINT32 dpi, BOOL is_smartphone)
{
    DWORD out_size;
    DWORD cfg;
	BSP_ARGS args;
	KernelIoControl(IOCTL_GET_BSP_ARGS, NULL, 0, 
					&args, sizeof(BSP_ARGS), &out_size);

	cfg=args.eBootCFG.drvCfg[CFG_LCD_PANEL];
    NKDbgPrintfW(TEXT("panel select: %X.\r\n"), cfg);


//    NKDbgPrintfW(TEXT("lcd panel cfg 0x%x, dual_panel_mode %d.\r\n"), cfg, dual_panel_mode);

    XllpLCDInitTopoly(&XllpLCD, cfg);

    KernelIoControl(IOCTL_HAL_SET_LCD, &XllpLCD, sizeof(XLLP_LCD_T), NULL, 0, &out_size);    

}

void set_lcd_domain(BOOL enable)
{
#if 0
    HANDLE pic_drv;
    DWORD domain=PIC_DOMAIN_DEBUG_3V;

    pic_drv = CreateFile(PIC_FILE_NAME, 0, 0, NULL, 0, 0, NULL);

    if (!pic_drv)
        ERRORMSG(1, (TEXT("open pic file failed!\r\n")));

    if(!DeviceIoControl(pic_drv, enable?(PIC_ENABLE_DOMAIN):(PIC_DISABLE_DOMAIN), &domain, sizeof(domain), 
                        0,0,0,0))
    {
        ERRORMSG(1,(_T("Error %s domain for LCD.\r\n"), enable? _T("enabling"):_T("disabling")));
        return;
    }

    CloseHandle(pic_drv);
#endif	
}
